/*
Pic Resizer : an easy to use program to resize your pictures
Copyright (C) 2009  Kévin Gomez <geek63@gmail.com>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#include "ProfilesManager.h"

ProfilesManager::ProfilesManager(QString profils_file)
{
    profils = new QSettings(profils_file, QSettings::NativeFormat);
}

Profil ProfilesManager::add(QString name, int height, int width, bool save_prop)
{

    profils->beginGroup(name);
    profils->setValue("name", name);
    profils->setValue("height", height);
    profils->setValue("width", width);
    profils->setValue("save_proportions", save_prop);
    profils->endGroup();

    Profil profil = {name, width, height, save_prop};

    return profil;
}

QList<Profil> ProfilesManager::get()
{
    QStringList groups = profils->childGroups();
    QList<Profil> profils_l;

    for (int i = 0; i < groups.size(); ++i)
    {
        profils_l << get(groups.at(i));
    }

    return profils_l;
}

Profil ProfilesManager::get(QString profil_id)
{
    profils->beginGroup(profil_id);

    Profil profil = {
                     profils->value("name").toString(),
                     profils->value("width").toInt(),
                     profils->value("height").toInt(),
                     profils->value("save_proportions").toBool()
                    };

    profils->endGroup();

    return profil;
}

void ProfilesManager::remove(QString profil)
{
    profils->remove(profil);
}
